package interviewpreparationkit.sorting

/**
 * [Mark and Toys](https://www.hackerrank.com/challenges/mark-and-toys)
 */
// Complete the maximumToys function below.
fun maximumToys(prices: Array<Int>, k: Int): Int {
    val priceList = prices.sorted().toMutableList()
    var ans = 0
    var sum = 0
    for (i in priceList) {
        sum += i
        if (sum <= k) {
            ans++
        } else {
            break
        }
    }
    return ans
}